package com.happystreet.engine
{
	import com.happystreet.config.GameConfig;
	import com.happystreet.info.WallInfo;
	
	import flash.display.MovieClip;
	
	public class ShopWall extends CoreObject
	{
		private var wallFloorNum:int;
		public var wallRightBound:int;
		public var wallLeftBound:int;
		public var wallTopPosX:int;
		private var shapeMask:CoreObject;
		public var wallInfo:WallInfo;
		public var shapeLineout:CoreObject;
		public var wallTopWidth:int;

		public function ShopWall(className:String=null)
		{
			super(className);
		}
		/**
		 *创建商店墙壁 
		 * @param info			信息数据
		 * @param level			等级
		 * @param floorList		地板列表
		 * @param sName			元件名字
		 * 
		 */		
		public function buildWall(info:WallInfo, level:int, floorList:Array, sName:String):void
		{
			var layOut:int;
			var halfHeight:int;
			var wallLeft:CoreObject;
			var wallRight:CoreObject;
			var _local14:int;
			var wall:CoreObject;
			this.wallInfo = info;
			floorList.push(this);
			this.wallFloorNum = floorList.length;
			var totalHeight:int = -(GameConfig.SHOP_WALL_HEIGHT * floorList.length);
			if (this.wallFloorNum == 1)
			{
				layOut = GameConfig.getShopLayout(level)[0];
				halfHeight = -(Math.floor(layOut / 2));
			}
			else
			{
				halfHeight = (floorList[(this.wallFloorNum - 2)].wallTopPosX + info.bottomLeftOffset);
				halfHeight = (floorList[(this.wallFloorNum - 2)].wallTopWidth - (info.bottomLeftOffset + info.bottomRightOffset));
			}
			this.shapeMask = new CoreObject();
			this.shapeMask.graphics.beginFill(0x333333, 1);
			this.shapeMask.graphics.drawRect(halfHeight, totalHeight, layOut, GameConfig.SHOP_WALL_HEIGHT);
			this.shapeMask.graphics.endFill();
			if (info.leftSymbolName != null)
			{
				wallLeft = new CoreObject(info.leftSymbolName);
				wallLeft.alignTo(halfHeight, totalHeight, CoreObject.ALIGN_RIGHT);
				this.shapeMask.add(wallLeft);
			}
			if (info.rightSymbolName != null)
			{
				wallRight = new CoreObject(info.rightSymbolName);
				wallRight.alignTo((halfHeight + layOut), totalHeight);
				this.shapeMask.add(wallRight);
			}
			this.add(this.shapeMask);
			this.wallTopPosX = (halfHeight - info.topLeftOffset);
			this.wallTopWidth = ((layOut + info.topLeftOffset) + info.topRightOffset);
			this.wallLeftBound = (halfHeight - Math.max(info.topLeftOffset, info.bottomLeftOffset));
			this.wallRightBound = ((halfHeight + layOut) + Math.max(info.topRightOffset, info.bottomRightOffset));
			var _local8:int = (Math.ceil((this.width / GameConfig.SHOP_WALL_TILE_SIZE)) + 2);
			var _local9:int = Math.floor((this.height / GameConfig.SHOP_WALL_TILE_SIZE));
			var _local10:int = ((Math.ceil(((halfHeight - 20) / GameConfig.SHOP_WALL_TILE_SIZE)) * GameConfig.SHOP_WALL_TILE_SIZE) - GameConfig.SHOP_WALL_TILE_SIZE);
			var i:int;
			while (i < _local8)
			{
				_local14 = 0;
				while (_local14 < _local9)
				{
					wall = new CoreObject(sName);
					wall.alignTo((_local10 + (GameConfig.SHOP_WALL_TILE_SIZE * i)), (totalHeight + (GameConfig.SHOP_WALL_TILE_SIZE * _local14)));
					this.add(wall);
					_local14++;
				}
				i++;
			}
			this.mask = this.shapeMask;
		}
	}
}